package com.gking.centerSystem.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.centerSystem.entity.AiServiceRecord;
import com.gking.centerSystem.entity.dto.PagingQueryAiServiceRecordDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AiServiceRecordMapper extends BaseMapper<AiServiceRecord> {


    /**
     * 分页条件查询的日志信息
     *
     * @param page            分页信息
     * @param account         访问者账号
     * @param nickname        访问者昵称
     * @param userId          用户id
     * @param userMessage     向AI提问的消息
     * @param description     对于此次提问的日志描述
     * @param responseStatus  响应状态
     * @return 分页条件查询的日志列表
     */
    @Select("<script>" +
            "SELECT DISTINCT l.*,  u.account, u.nickname " +
            "FROM ai_service_record l " +
            "LEFT JOIN user u ON u.id = l.accessUserId " +
            "WHERE " +
            "l.isDelete = 0 " +
            "<if test='account != null and account.trim() neq \"\"'> AND u.account LIKE CONCAT('%', #{account}, '%') </if> " +
            "<if test='nickname != null and nickname.trim() neq \"\"'> AND u.nickname LIKE CONCAT('%', #{nickname}, '%') </if> " +
            "<if test='userId != null and userId.trim() neq \"\"'> AND u.id LIKE CONCAT('%', #{userId}, '%') </if> " +
            "<if test='userMessage != null and userMessage.trim() neq \"\"'> AND l.userMessage LIKE CONCAT('%', #{userMessage}, '%') </if> " +
            "<if test='description != null and description.trim() neq \"\"'> AND l.description LIKE CONCAT('%', #{description}, '%') </if> " +
            "<if test='responseStatus != null'> AND l.responseStatus = #{responseStatus} </if> " +

            "ORDER BY l.createTime DESC " +
            "</script>")
    @InterceptorIgnore(tenantLine = "true")
    IPage<PagingQueryAiServiceRecordDto> findAiServiceRecordByCriteria(Page<PagingQueryAiServiceRecordDto> page,
                                                                       @Param("account") String account,
                                                                       @Param("nickname") String nickname,
                                                                       @Param("userId") String userId,
                                                                       @Param("userMessage") String userMessage,
                                                                       @Param("description") String description,
                                                                       @Param("responseStatus") Integer responseStatus );


}
